define(['jquery', 'bootstrap', 'utilback', 'table', 'form', 'myfileinput','ztree'], function($, undefined, Utilback, Table, Form, myfileInput,ztree) {

	var Controller = {
		config: {
			get_url: '/user/read/detail', // 获取用户详情
		},
		init: function() {
			this.initDic();
			this.initParam();
			this.initParam2();
			this.initParam3();
			this.initParam4();
			this.initParam5();
			this.initParam6();
			this.initParam7();
            this.initParam8();
			$('[href="#param6"]').click();
		},
		initDic:function(){
			var i = 0;
			// 初始化表格参数配置
			$('[href="#dic"]').on('click',function(){
				Table.api.init({
					singleSelect: true,
					extend: {
						index_url: './json/overhaulMaintenance.json', // 查询列表
						add_url: 'overhaulCoupler.html', // 新增页面
						edit_url: 'overhaulCoupler.html', // 修改页面
						del_url: '/overhaulMaintenance', // 删除
						multi_url: '/overhaulMaintenance',
						guidIn_url: 'driverGuidIn.html', //添加导入页面
                        carNum_url:'trackCarRecord.html',
						info_url: 'serviceAnnalplan.html', //信息的页面
					}
				});

                if(i === 0){
					var table = $("#dicTable");
	
					// 初始化表格
					table.bootstrapTable({
						url: $.fn.bootstrapTable.defaults.extend.index_url,
						toolbar:'#toolbar',
						method: 'get',
						columns: [
							[{
									field: 'state',checkbox: true},
								{field: 'id',title: 'ID'},
								{
									field: 'wagonNumber',
									title: '车号',
		                            formatter : function (value,row,index) {
		    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.carNum_url);
		}
								},
								{
									field: 'driveName',
									title: "设备名称"
								},
								{
									field: 'models',
									title: "规格型号"
								},
								{
									field: 'startDate',
									title: "探伤日期"
								},
								{
									field: 'endDate',
									title: "下次探伤日期"
								},
								{
									field: 'maintainCompany',
									title: "探伤单位"
								},
								{
									field: 'repairSite',
									title: '钩与钩耳间隙'
								}, {
									field: 'principal',
									title: "钩耳孔与钩舌销孔直径磨耗"
								},
								{
									field: 'upkeepCosts',
									title: "大钩距轨面高度"
								},
								{
									field: 'repairItems',
									title: "全开锁最大面积"
								},
								{
									field: 'testRunTime',
									title: "小车购距轨面高度"
								},
								{
									field: 'testRunKilometre',
									title: "钩舌销与钩孔或钩耳孔间距"
								},
								{
									field: 'testRunResult',
									title: "探伤负责人"
								},
								{
									field: 'testRunConclusion',
									title: "验收人"
								},
								{
									field: 'acceptanceOpinion',
									title: "探伤结论"
								},
								{
									field: 'remark',
									title: "处理意见"
								},
								{
									field: 'operate',
									title: __('Operate'),
									events: Table.api.events.operate,
									formatter: function(value, row, index) {
										return Table.api.formatter.operate.call(this, value, row, index, table);
									}
								},
							]
						]
					});
	
					// 为表格绑定事件
					Table.api.bindevent(table);
					i++;
                }
			});
		},
        // 大修
		initParam:function(){
			var i = 0;
                var paramTable = $('#paramTable');
                $('[href="#param"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            add_url: 'overhaulHeavyAdd.html', // 新增页面
							edit_url: 'overhaulHeavyAdd.html', // 修改页面
                            del_url: '/overhaulMaintenance', // 删除
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                            multi_url: '/overhaulMaintenance', 
                            info_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable.bootstrapTable({
                            toolbar:'#toolbar1',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'wagonNumber', title: '车号',formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.info_url);
}},
                                    {field: 'driveName', title: "设备名称"},
                                    {field: 'models', title: "规格型号"},
                                    {field: 'startDate', title: "开始日期"},
                                    {field: 'endDate', title: "完成日期"},
                                    {field: 'maintenanceReasons', title: "维修原因"},
                                    {field: 'maintainCompany', title: '承修单位'},
                                    {field: 'repairSite', title: '修理地点'},
                                    {field: 'principal', title: "修理负责人"},
                                    {field: 'upkeepCosts', title: "维修费用"},
                                    {field: 'upkeepList', title: "维修事项"},
                                    {field: 'testRunData', title: "试运日期"},
                                    {field: 'testRunSection', title: "试运区间"},
                                    {field: 'testRunDistance', title: "试运公里数"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable);
                        i++;
                    }
                });
		},
		initParam2:function(){
			var i = 0;
                var paramTable2 = $('#paramTable2');
                $('[href="#param2"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            del_url: '/overhaulMaintenance', // 删除
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                            edit_url:'overhaulTrouble.html',
                            add_url:'overhaulTrouble.html',
                            multi_url: '/overhaulMaintenance', 
                            carNum_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable2.bootstrapTable({
                            toolbar:'#toolbar2',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'time', title: '时间'},
                                    {field: 'repaireUnit', title: "报修单位"},
                                    {field: 'carNum', title: "车号",formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.carNum_url);
}},
                                    {field: 'repairMan', title: "报修人"},
                                    {field: 'troubles', title: "故障现象"},
                                    {field: 'check', title: "审核"},
                                    {field: 'arrangeWork', title: '安排工区'},
                                    {field: 'repairSite', title: '维修情况'},
                                    {field: 'principal', title: "维修人"},
                                    {field: 'accepter', title: "验收人"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable2);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable2);
                        i++;
                    }
                });
		},
		initParam3:function(){
			var i = 0;
                var paramTable3 = $('#paramTable3');
                $('[href="#param3"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            add_url: 'overhaulRpair.html', // 新增页面
							edit_url: 'overhaulRpair.html', // 修改页面
							guidIn_url: 'driverGuidIn.html', //添加导入页面
                            del_url: '/overhaulMaintenance', // 删除
                            multi_url: '/overhaulMaintenance', 
                            carNum_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable3.bootstrapTable({
                            toolbar:'#toolbar3',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'data', title: '日期'},
                                    {field: 'belongWork', title: "所属工区"},
                                    {field: 'homeworkCar', title: "作业车号",formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.carNum_url);
}},
                                    {field: 'troubles', title: "故障现象"},
                                    {field: 'resonAnalysis', title: "原因分析"},
                                    {field: 'prevention', title: "对策措施活预防方法"},
                                    {field: 'handingInfo', title: '处理情况'},
                                    {field: 'faultType', title: '故障类型'},
                                    {field: 'awayDate', title: "销号日期"},
                                    {field: 'repairSite', title: "责任检修工区"},
                                    {field: 'repairMan', title: "主修人"},
                                    {field: 'remarks', title: "备注"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable3);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable3);
                        i++;
                    }
                });
		},
		initParam4:function(){
			var i = 0;
                var paramTable4 = $('#paramTable4');
                $('[href="#param4"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            add_url: 'overhaulcrack.html', // 新增页面
							edit_url: 'overhaulcrack.html', // 修改页面
                            del_url: '/overhaulMaintenance', // 删除
                            multi_url: '/overhaulMaintenance', 
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                        	info_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable4.bootstrapTable({
                            toolbar:'#toolbar4',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'carNum', title: '车号',formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.info_url);
}},
                                    {field: 'deviceName', title: "设备名称"},
                                    {field: 'specifications', title: "规格型号"},
                                    {field: 'flawDate', title: "探伤日期"},
                                    {field: 'nextFlawDate', title: "下次探伤日期"},
                                    {field: 'flawReason', title: "探伤原因"},
                                    {field: 'flawUnit', title: '探伤单位'},
                                    {field: 'flawNum', title: '合格证编号'},
                                    {field: 'flawMileage', title: "本次探伤里程"},
                                    {field: 'flawMan', title: "探伤负责人"},
                                    {field: 'accepter', title: "验收人"},
                                    {field: 'revolution', title: "探伤结论"},
                                    {field: 'dealSuggestion', title: '处理意见'},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable4);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable4);
                        i++;
                    }
                });
		},
        // 定期保养
		initParam5:function(){
			var i = 0;
                var paramTable5 = $('#paramTable5');
                $('[href="#param5"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            del_url: '/overhaulMaintenance', // 删除
                            add_url: 'overhaulMaintenanceAdd.html', // 新增页面
							edit_url: 'overhaulMaintenanceAdd.html', // 修改页面
							guidIn_url: 'driverGuidIn.html', //添加导入页面
                            multi_url: '/overhaulMaintenance', 
                            carNum_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable5.bootstrapTable({
                            toolbar:'#toolbar5',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'carNum', title: '车号',formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.carNum_url);
}},
                                    {field: 'deviceName', title: "设备名称"},
                                    {field: 'specifications', title: "规格型号"},
                                    {field: 'startDate', title: "开始日期"},
                                    {field: 'endDate', title: "完成日期"},
                                    {field: 'maintainClass', title: "保养类别"},
                                    {field: 'whetherOntime', title: '是否按期保养'},
                                    {field: 'whetherSpecification', title: '是否按规定保养'},
                                    {field: 'flawUnit', title: "保养单位"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable5);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable5);
                        i++;
                    }
                });
		},
		initParam6:function(){
			var i = 0;
                var paramTable6 = $('#paramTable6');
                $('[href="#param6"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            del_url: '/overhaulMaintenance', // 删除
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                            add_url: 'overhaulDay.html', // 新增页面
							edit_url: 'overhaulDay.html', // 修改页面
                            multi_url: '/overhaulMaintenance', 
                            carNum_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable6.bootstrapTable({
                            toolbar:'#toolbar6',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'carNum', title: '车号',formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.carNum_url);
}},
                                    {field: 'deviceName', title: "设备名称"},
                                    {field: 'specifications', title: "规格型号"},
                                    {field: 'startDate', title: "开始日期"},
                                    {field: 'endDate', title: "完成日期"},
                                    {field: 'intervalDate', title: "间隔天数"},
                                    {field: 'runKiol', title: '走行公里'},
                                    {field: 'coapling', title: '连挂平车'},
                                    {field: 'checkCar', title: "出车检查"},
                                    {field: 'handCardflaw', title: "收车保养"},
                                    {field: 'machineOil', title: "机油（kg）"},
                                    {field: 'fuelOil', title: "燃油（L）"},
                                    {field: 'gearOil', title: "齿轮油（kg）"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable6);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable6);
                        i++;
                    }
                });
                // 树形结构显示
             var zTree;
            var setting = {
              view: {
                dblClickExpand: false,//双击节点时，是否自动展开父节点的标识
                showLine: true,//是否显示节点之间的连线
                fontCss:{'color':'black','font-weight':'bold'},//字体样式函数
                selectedMulti: false //设置是否允许同时选中多个节点
              },
              check:{
                //chkboxType: { "Y": "ps", "N": "ps" },
                chkStyle: "checkbox",//复选框类型
                enable: true //每个节点上是否显示 CheckBox 
              },
              data: {
                simpleData: {//简单数据模式
                  enable:true,
                  idKey: "id",
                  pIdKey: "pId",
                  rootPId: ""
                }
              },
              callback: {
                beforeClick: function(treeId, treeNode) {
                  zTree = $.fn.zTree.getZTreeObj("user_tree");
                  if (treeNode.isParent) {
                    zTree.expandNode(treeNode);//如果是父节点，则展开该节点
                  }else{
                    zTree.checkNode(treeNode, !treeNode.checked, true, true);//单击勾选，再次单击取消勾选
                  }
                }
              }
            };
            var zNodes =[
                          { id:1, pId:0, name:"车辆故障检修", open:false},
                          { id:1, pId:0, name:"车辆检修", open:false},
                         ];
                         
                $(document).ready(function(){
                  $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                });

		},
		initParam7:function(){
			var i = 0;
                var paramTable7 = $('#paramTable7');
                $('[href="#param7"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            del_url: '/overhaulMaintenance', // 删除
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                            add_url: 'overhaulMaintenanceAdd.html', // 新增页面
							edit_url: 'overhaulMaintenanceAdd.html', // 修改页面
                            multi_url: '/overhaulMaintenance', 
                            info_url: 'trackCarRecord.html', //信息的页面
                        }
                    });
                    if(i === 0){
                        
                        // 初始化表格
                        paramTable7.bootstrapTable({
                            toolbar:'#toolbar7',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'carNum', title: '车号',formatter : function (value,row,index) {
    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.info_url);
}},
                                    {field: 'deviceName', title: "设备名称"},
                                    {field: 'specifications', title: "规格型号"},
                                    {field: 'checkDate', title: "制动检验日期"},
                                    {field: 'checkUnit', title: "制动校验单位"},
                                    {field: 'brakeType', title: "制动机类型"},
                                    {field: 'qualifiedNum', title: '合格证编号'},
                                    {field: 'nextCheckDate', title: '下次校验日期'},
                                    {field: 'checkMan', title: "检测人"},
                                    {field: 'accepter', title: "验收人"},
                                    {field: 'conclusion', title: "校验结论"},
                                    {field: 'dealSuggestion', title: "处理意见"},
                                    {field: 'remarks', title: "备注"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable7);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable7);
                        i++;
                    }
                });
		},
        // 小修
        initParam8:function(){
            var i = 0;
                var paramTable8 = $('#paramTable8');
                $('[href="#param8"]').on('click',function(){
                    Table.api.init({
                        singleSelect:true,
                        extend:{
                            index_url: './json/overhaulMaintenance.json', // 查询列表
                            del_url: '/overhaulMaintenance', // 删除
                            add_url: 'overhaulHeavyAdd.html', // 新增页面
                            guidIn_url: 'driverGuidIn.html', //添加导入页面
                            edit_url: 'overhaulHeavyAdd.html', // 修改页面
                            multi_url: '/overhaulMaintenance', 
                            info_url: 'serviceAnnalplan.html', //信息的页面
                            CarNum_url:'trackCarRecord.html',
                        }
                    });
                    if(i === 0){
                        // 初始化表格
                        paramTable8.bootstrapTable({
                            toolbar:'#toolbar8',
                            url:$.fn.bootstrapTable.defaults.extend.index_url,
                            method:'get',
                            columns:[
                                [
                                    {field: 'state', checkbox: true,},
                                    {field: 'id', title: 'ID'},
                                    {field: 'carNum', title: '车号',formatter : function (value,row,index) {
                                    return Table.api.formatter.addtabs(value,row,index,$.fn.bootstrapTable.defaults.extend.CarNum_url);
                                }},
                                    {field: 'deviceName', title: "设备名称"},
                                    {field: 'specifications', title: "规格型号"},
                                    {field: 'checkDate', title: "制动检验日期"},
                                    {field: 'checkUnit', title: "制动校验单位"},
                                    {field: 'brakeType', title: "制动机类型"},
                                    {field: 'qualifiedNum', title: '合格证编号'},
                                    {field: 'nextCheckDate', title: '下次校验日期'},
                                    {field: 'checkMan', title: "检测人"},
                                    {field: 'accepter', title: "验收人"},
                                    {field: 'conclusion', title: "校验结论"},
                                    {field: 'dealSuggestion', title: "处理意见"},
                                    {field: 'remarks', title: "备注"},
                                    {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                            return Table.api.formatter.operate.call(this, value, row, index,paramTable8);
                                }}
                                ]
                            ]
                        });
                        Table.api.bindevent(paramTable8);
                        i++;
                    }
                });
        },
		edit: function() { // 初始化编辑页面
			Form.api.bindevent($("form[role=form]"));
            Util.api.initSelectTree({
                checkParent: true,
                parentEle: 'department',
                url: './json/list.json',
                data: JSON.stringify({keyword:''}),
                resetData: function(data) {
                   for(var i=0;i<data.length;i++) {
                       if(data[i].leaf == 0) {
                           data[i]['open'] = true;
                       }
                       data[i]['pId'] = data[i].parentId;
                       data[i]['name'] = data[i].deptName;
                   }
                   return data;
                }
            });
            var id = Util.api.query('id');
            var t = Util.api.query('t');
            if(id && t === 'U') {
                Form.api.fill($('#edit-form'), Controller.config.get_url, id, function(data) {
                });
            }
		},
		update: function() {
			Form.api.bindevent($("form[role=form]"));
			Util.api.ajax({
				type: 'GET',
				url: '/user/read/current'
			}, function(data) {
				$('#edit-form').autofill(data);
			});
		}
	};
	return Controller;

	function changeAgentContent() {
		document.getElementById("inputFileAgent").value = document.getElementById("inputFile").value;
	}
});